package com.stylefeng.guns.modular.pay.exception;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * 统一异常处理
 * @author Administrator
 *
 */
@ControllerAdvice
public class BusExceptionHandle {
	private final static Logger logger = LoggerFactory.getLogger(BusExceptionHandle.class);

	@ExceptionHandler(value = Exception.class)
	@ResponseBody
	public Result handle(Exception e) {
		if (e instanceof BusException) {// 判断异常是否为自己定义的BusException
			BusException busException = (BusException) e;
			return ResultUtil.error(busException.getRetCode(), busException.getErrMsg(), ((BusException) e).getKey());
		} else if (e instanceof Exception) {
			return ResultUtil.error("unkonw.exception", "未知错误","");
		}
		return null;
	}
}
